package com.itkaien.javaeebased.reflectproxyprogarm;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class App {


    public static void main(String[] args) {

        Star bigStar = new BigStar("鸡哥");
        Star star = (Star) Proxy.newProxyInstance(ProxyUtil.class.getClassLoader(), new Class[]{Star.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理开始");
                if ("sing".equals(method.getName())) {
                    System.out.println("代理开始唱歌");
                } else {
                    System.out.println("代理开始跳舞");
                }
                Object result = method.invoke(bigStar, args);
                System.out.println("代理结束");
                return result;
            }
        });
        star.sing("鸡哥");
    }
}
